# include <iostream>
# include <unordered_map>
# include <algorithm>
using namespace std;
vector<vector<string>>groupWords(vector<string> strs) {
	unordered_map<string,vector<string>> strMap;
	vector<vector<string>> result;
	for(const string& str : strs) {
		string strSort=str;
		sort(strSort.begin(),strSort.end());
		strMap[strSort].push_back(str);
	}
	for(const auto& pair:strMap) {
		result.push_back(pair.second);
	}
	return result;
}
void printGroupWords(vector<vector<string>> result) {
	for(const vector<string> & vec:result) {
		for(const string str:vec) {
			cout<<str<<" ";
		}
		cout<<endl;
	}
}
int main() {
	vector<string> words= {"eat", "tea", "tan", "ate", "nat", "bat"};
	vector<vector<string>>result= groupWords(words);
	printGroupWords(result);
	return 0;
}
